﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;
using System.Windows.Media;
using System.Windows.Media.Media3D;

namespace TestDxfDocument
{

    class Threeedgecountersinkdril
    {
        public static void _Threeedgecountersinkdril(Dictionary<string, Object> data)//三刃锪钻
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层


            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数


            //double scale = 1; //放大系数

            //double D = 4.3;
            //double d1 = 1.3;
            //double d = 4;
            //double l = 40;
            //double l1 = 3.5;
            //double l2 = 32;

            //String ccms = "yzb";
            //String ccms = "msyzb";

            //double jd = 90;
            //double jd = 60;


            String ccms = Convert.ToString(data["ccms"]);
            double jd = Convert.ToDouble(data["jd"]);


            if (ccms == "yzb" && jd == 90)//90°圆柱柄
            {
                //double D = 29.34;
                //double d1 = 4.26;
                //double d = 13;
                //double l = 73.42;
                //double l1 = 17.48;
                //double l2 = 46.19;

                double D = Convert.ToDouble(data["dcx"]) * scale;
                double d1 = Convert.ToDouble(data["dc"]) * scale;
                double d = Convert.ToDouble(data["dconms"]) * scale;
                double l = Convert.ToDouble(data["oal"]) * scale;
                double l1 = Convert.ToDouble(data["lh"]) * scale;
                double l2 = Convert.ToDouble(data["ls"]) * scale;


                Vector2 v1 = new Vector2(-2, 0);
                Vector2 v2 = new Vector2(l + 2, 0);
                Vector2 v3 = new Vector2(0, d1 / 2);
                Vector2 v4 = new Vector2((D - d1) / 2 * Math.Tan((90 - jd / 2) * pi / 180), D / 2);
                Vector2 v5 = new Vector2(l1, v4.Y - (l1 - v4.X) / 30 / 2);
                Vector2 v6 = new Vector2(v5.X + l1 * 5.89 / 17.48, (d * 9.26 / 13) / 2);
                Vector2 v7 = new Vector2(l - l2, v6.Y);
                Vector2 v8 = new Vector2(v7.X + d / 2 - v7.Y, d / 2);
                Vector2 v9 = new Vector2(l - (d / 2 - v7.Y), v8.Y);
                Vector2 v10 = new Vector2(l, v7.Y);
                Vector2 v11 = new Vector2(v10.X, -v10.Y);
                Vector2 v12 = new Vector2(v9.X, -v9.Y);
                Vector2 v13 = new Vector2(v8.X, -v8.Y);
                Vector2 v14 = new Vector2(v7.X, -v7.Y);
                Vector2 v15 = new Vector2(v6.X, -v6.Y);
                Vector2 v16 = new Vector2(v5.X, -v5.Y);
                Vector2 v17 = new Vector2(v4.X, -v4.Y);
                Vector2 v18 = new Vector2(v3.X, -v3.Y);
                Vector2 v19 = new Vector2(0, d1 / 4);
                Vector2 v20 = new Vector2(v4.X, D * 9.78 / 29.34);
                Vector2 v21 = new Vector2(v5.X, D * 8.81 / 29.34);
                Vector2 v22 = new Vector2(l1 * 22.03 / 17.48, 0);
                Vector2 v23 = new Vector2(l1 * 20.97 / 17.48, -(D * 5.32 / 29.34));
                Vector2 v24 = new Vector2(v5.X, -(D * 4.61 / 29.34));
                Vector2 v25 = new Vector2(v4.X, -(D * 3.61 / 29.34));
                Vector2 v26 = new Vector2(0, -d1 / 4);


                Line line1 = new Line(v1, v2);
                line1.Layer = centre;
                line1.Linetype = Linetype.DashDot;
                line1.LinetypeScale = 3;
                dxf.AddEntity(line1);

                LwPolyline line2 = new LwPolyline();
                line2.Vertexes.Add(new LwPolylineVertex(v3));
                line2.Vertexes.Add(new LwPolylineVertex(v4));
                line2.Vertexes.Add(new LwPolylineVertex(v5));
                line2.Vertexes.Add(new LwPolylineVertex(v6));
                line2.Vertexes.Add(new LwPolylineVertex(v7));
                line2.Vertexes.Add(new LwPolylineVertex(v8));
                line2.Vertexes.Add(new LwPolylineVertex(v9));
                line2.Vertexes.Add(new LwPolylineVertex(v10));
                line2.Vertexes.Add(new LwPolylineVertex(v11));
                line2.Vertexes.Add(new LwPolylineVertex(v12));
                line2.Vertexes.Add(new LwPolylineVertex(v13));
                line2.Vertexes.Add(new LwPolylineVertex(v14));
                line2.Vertexes.Add(new LwPolylineVertex(v15));
                line2.Vertexes.Add(new LwPolylineVertex(v16));
                line2.Vertexes.Add(new LwPolylineVertex(v17));
                line2.Vertexes.Add(new LwPolylineVertex(v18));
                line2.Vertexes.Add(new LwPolylineVertex(v3));
                fun.PolyFill(dxf, line2, 0.1, contour);

                LwPolyline line3 = new LwPolyline();
                line3.Vertexes.Add(new LwPolylineVertex(v19));
                line3.Vertexes.Add(new LwPolylineVertex(v20));
                line3.Vertexes.Add(new LwPolylineVertex(v21));
                line3.Vertexes.Add(new LwPolylineVertex(v22));
                line3.Vertexes.Add(new LwPolylineVertex(v23));
                line3.Vertexes.Add(new LwPolylineVertex(v24));
                line3.Vertexes.Add(new LwPolylineVertex(v25));
                line3.Vertexes.Add(new LwPolylineVertex(v26));
                line3.Vertexes.Add(new LwPolylineVertex(v19));
                line3.Vertexes[3].Bulge = Math.Tan(-73 * pi / 180 / 4);
                fun.PolyFill(dxf, line3, 0.1, contour);


                LwPolyline line4 = new LwPolyline();
                line4.Vertexes.Add(new LwPolylineVertex(v4));
                line4.Vertexes.Add(new LwPolylineVertex(v20));
                fun.PolyFill(dxf, line4, 0.1, contour);

                LwPolyline line5 = new LwPolyline();
                line5.Vertexes.Add(new LwPolylineVertex(v5));
                line5.Vertexes.Add(new LwPolylineVertex(v21));
                fun.PolyFill(dxf, line5, 0.1, contour);

                LwPolyline line6 = new LwPolyline();
                line6.Vertexes.Add(new LwPolylineVertex(v6));
                line6.Vertexes.Add(new LwPolylineVertex(v15));
                fun.PolyFill(dxf, line6, 0.1, contour);

                LwPolyline line7 = new LwPolyline();
                line7.Vertexes.Add(new LwPolylineVertex(v7));
                line7.Vertexes.Add(new LwPolylineVertex(v14));
                fun.PolyFill(dxf, line7, 0.1, contour);

                LwPolyline line8 = new LwPolyline();
                line8.Vertexes.Add(new LwPolylineVertex(v8));
                line8.Vertexes.Add(new LwPolylineVertex(v13));
                fun.PolyFill(dxf, line8, 0.1, contour);

                LwPolyline line9 = new LwPolyline();
                line9.Vertexes.Add(new LwPolylineVertex(v9));
                line9.Vertexes.Add(new LwPolylineVertex(v12));
                fun.PolyFill(dxf, line9, 0.1, contour);

                LwPolyline line10 = new LwPolyline();
                line10.Vertexes.Add(new LwPolylineVertex(v16));
                line10.Vertexes.Add(new LwPolylineVertex(v24));
                fun.PolyFill(dxf, line10, 0.1, contour);

                LwPolyline line11 = new LwPolyline();
                line11.Vertexes.Add(new LwPolylineVertex(v17));
                line11.Vertexes.Add(new LwPolylineVertex(v25));
                fun.PolyFill(dxf, line11, 0.1, contour);

                //标注
                double height = 1 * scale;
                double arrowsize = 1 * scale;
                double exline = 1 * scale;

                fun.dimrot1(dxf, v4, v17, 90, l * 0.4, height, arrowsize, exline, 0, "DCX=" + D/scale, "", "");
                fun.dimrot1(dxf, v3, v18, 90, l * 0.1, height, arrowsize, exline, 0, "DC=" + d1 / scale, "", "");
                fun.dimrot1(dxf, v9, v12, -90, l * 0.1, height, arrowsize, exline, 0, "DCONMS=" + d / scale, "", "");
                fun.dimrot1(dxf, v3, v10, 0, l * 0.4, height, arrowsize, exline, 0, "OAL=" + l / scale, "", "");
                fun.dimrot1(dxf, v3, v5, 0, l * 0.2, height, arrowsize, exline, 0, "LH=" + l1 / scale, "", "");
                fun.dimrot1(dxf, v7, v10, 0, l * 0.1, height, arrowsize, exline, 0, "LS=" + l2 / scale, "", "");


                fun.jdbz2(dxf, new Line(v18, v17), new Line(v3, v4), l * 0.1, height, arrowsize, exline, "" + jd + "°", "", "");

                fun.jt(dxf, new Vector2(v17.X + (v16.X - v17.X) / 2, v17.Y + (v16.Y - v17.Y) / 2), -45, l1 / 3, 1, "1:30");


            }

            if (ccms == "yzb" && jd == 60)//60°圆柱柄
            {
                //double D = 25.59;
                //double d1 = 3.97;
                //double d = 11.56;
                //double l = 74.82;
                //double l1 = 22.99;
                //double l2 = 42.71;

                double D = Convert.ToDouble(data["dcx"]) * scale;
                double d1 = Convert.ToDouble(data["dc"]) * scale;
                double d = Convert.ToDouble(data["dconms"]) * scale;
                double l = Convert.ToDouble(data["oal"]) * scale;
                double l1 = Convert.ToDouble(data["lh"]) * scale;
                double l2 = Convert.ToDouble(data["ls"]) * scale;


                Vector2 v1 = new Vector2(-2, 0);
                Vector2 v2 = new Vector2(l + 2, 0);
                Vector2 v3 = new Vector2(0, d1 / 2);
                Vector2 v4 = new Vector2((D - d1) / 2 * Math.Tan((90 - jd / 2) * pi / 180), D / 2);
                Vector2 v5 = new Vector2(l1, v4.Y - (l1 - v4.X) / 30 / 2);
                Vector2 v6 = new Vector2(v5.X + l1 * 5.11 / 22.99, (d * 8.13 / 11.56) / 2);
                Vector2 v7 = new Vector2(l - l2, v6.Y);
                Vector2 v8 = new Vector2(v7.X + d / 2 - v7.Y, d / 2);
                Vector2 v9 = new Vector2(l - (d / 2 - v7.Y), v8.Y);
                Vector2 v10 = new Vector2(l, v7.Y);
                Vector2 v11 = new Vector2(v10.X, -v10.Y);
                Vector2 v12 = new Vector2(v9.X, -v9.Y);
                Vector2 v13 = new Vector2(v8.X, -v8.Y);
                Vector2 v14 = new Vector2(v7.X, -v7.Y);
                Vector2 v15 = new Vector2(v6.X, -v6.Y);
                Vector2 v16 = new Vector2(v5.X, -v5.Y);
                Vector2 v17 = new Vector2(v4.X, -v4.Y);
                Vector2 v18 = new Vector2(v3.X, -v3.Y);
                Vector2 v19 = new Vector2(0, d1 / 2 * 3 / 4);
                Vector2 v20 = new Vector2(v4.X, D * 8.41 / 25.59 / 2);
                Vector2 v21 = new Vector2(v5.X, D * 7.54 / 25.59 / 2);
                Vector2 v22 = new Vector2(l1 * 26.98 / 22.99, 0);
                Vector2 v23 = new Vector2(l1 * 26.06 / 22.99, -(D * 4.67 / 25.59));
                Vector2 v24 = new Vector2(v5.X, -(D * 4.16 / 25.59));
                Vector2 v25 = new Vector2(v4.X, -(D * 3.45 / 25.59));
                Vector2 v26 = new Vector2(0, -d1 / 6);


                Line line1 = new Line(v1, v2);
                line1.Layer = centre;
                line1.Linetype = Linetype.DashDot;
                line1.LinetypeScale = 3;
                dxf.AddEntity(line1);

                LwPolyline line2 = new LwPolyline();
                line2.Vertexes.Add(new LwPolylineVertex(v3));
                line2.Vertexes.Add(new LwPolylineVertex(v4));
                line2.Vertexes.Add(new LwPolylineVertex(v5));
                line2.Vertexes.Add(new LwPolylineVertex(v6));
                line2.Vertexes.Add(new LwPolylineVertex(v7));
                line2.Vertexes.Add(new LwPolylineVertex(v8));
                line2.Vertexes.Add(new LwPolylineVertex(v9));
                line2.Vertexes.Add(new LwPolylineVertex(v10));
                line2.Vertexes.Add(new LwPolylineVertex(v11));
                line2.Vertexes.Add(new LwPolylineVertex(v12));
                line2.Vertexes.Add(new LwPolylineVertex(v13));
                line2.Vertexes.Add(new LwPolylineVertex(v14));
                line2.Vertexes.Add(new LwPolylineVertex(v15));
                line2.Vertexes.Add(new LwPolylineVertex(v16));
                line2.Vertexes.Add(new LwPolylineVertex(v17));
                line2.Vertexes.Add(new LwPolylineVertex(v18));
                line2.Vertexes.Add(new LwPolylineVertex(v3));
                fun.PolyFill(dxf, line2, 0.1, contour);

                LwPolyline line3 = new LwPolyline();
                line3.Vertexes.Add(new LwPolylineVertex(v19));
                line3.Vertexes.Add(new LwPolylineVertex(v20));
                line3.Vertexes.Add(new LwPolylineVertex(v21));
                line3.Vertexes.Add(new LwPolylineVertex(v22));
                line3.Vertexes.Add(new LwPolylineVertex(v23));
                line3.Vertexes.Add(new LwPolylineVertex(v24));
                line3.Vertexes.Add(new LwPolylineVertex(v25));
                line3.Vertexes.Add(new LwPolylineVertex(v26));
                line3.Vertexes.Add(new LwPolylineVertex(v19));
                line3.Vertexes[3].Bulge = Math.Tan(-67 * pi / 180 / 4);
                fun.PolyFill(dxf, line3, 0.1, contour);


                LwPolyline line4 = new LwPolyline();
                line4.Vertexes.Add(new LwPolylineVertex(v4));
                line4.Vertexes.Add(new LwPolylineVertex(v20));
                fun.PolyFill(dxf, line4, 0.1, contour);

                LwPolyline line5 = new LwPolyline();
                line5.Vertexes.Add(new LwPolylineVertex(v5));
                line5.Vertexes.Add(new LwPolylineVertex(v21));
                fun.PolyFill(dxf, line5, 0.1, contour);

                LwPolyline line6 = new LwPolyline();
                line6.Vertexes.Add(new LwPolylineVertex(v6));
                line6.Vertexes.Add(new LwPolylineVertex(v15));
                fun.PolyFill(dxf, line6, 0.1, contour);

                LwPolyline line7 = new LwPolyline();
                line7.Vertexes.Add(new LwPolylineVertex(v7));
                line7.Vertexes.Add(new LwPolylineVertex(v14));
                fun.PolyFill(dxf, line7, 0.1, contour);

                LwPolyline line8 = new LwPolyline();
                line8.Vertexes.Add(new LwPolylineVertex(v8));
                line8.Vertexes.Add(new LwPolylineVertex(v13));
                fun.PolyFill(dxf, line8, 0.1, contour);

                LwPolyline line9 = new LwPolyline();
                line9.Vertexes.Add(new LwPolylineVertex(v9));
                line9.Vertexes.Add(new LwPolylineVertex(v12));
                fun.PolyFill(dxf, line9, 0.1, contour);

                LwPolyline line10 = new LwPolyline();
                line10.Vertexes.Add(new LwPolylineVertex(v16));
                line10.Vertexes.Add(new LwPolylineVertex(v24));
                fun.PolyFill(dxf, line10, 0.1, contour);

                LwPolyline line11 = new LwPolyline();
                line11.Vertexes.Add(new LwPolylineVertex(v17));
                line11.Vertexes.Add(new LwPolylineVertex(v25));
                fun.PolyFill(dxf, line11, 0.1, contour);

                //标注
                double height = 1 * scale;
                double arrowsize = 1 * scale;
                double exline = 1 * scale;

                fun.dimrot1(dxf, v4, v17, 90, l * 0.4, height, arrowsize, exline, 0, "DCX=" + D / scale, "", "");
                fun.dimrot1(dxf, v3, v18, 90, l * 0.1, height, arrowsize, exline, 0, "DC=" + d1 / scale, "", "");
                fun.dimrot1(dxf, v9, v12, -90, l * 0.1, height, arrowsize, exline, 0, "DCONMS=" + d / scale, "", "");
                fun.dimrot1(dxf, v3, v10, 0, l * 0.4, height, arrowsize, exline, 0, "OAL=" + l / scale, "", "");
                fun.dimrot1(dxf, v3, v5, 0, l * 0.2, height, arrowsize, exline, 0, "LH=" + l1 / scale, "", "");
                fun.dimrot1(dxf, v7, v10, 0, l * 0.1, height, arrowsize, exline, 0, "LS=" + l2 / scale, "", "");


                fun.jdbz2(dxf, new Line(v18, v17), new Line(v3, v4), l * 0.1, height, arrowsize, exline, "" + jd + "°", "", "");

                fun.jt(dxf, new Vector2(v17.X + (v16.X - v17.X) / 2, v17.Y + (v16.Y - v17.Y) / 2), -45, l1 / 3, 1, "1:30");

            }

            if (ccms == "msyzb" && jd == 90)//90°莫氏圆锥柄
            {

                //double D = 28.58;
                //double d1 = 7.24;
                //double l = 98.65;
                //double l1 = 13.37;

                //double czc = 1;
                double db = 0;
                double ds = 0;
                double tg = 0;

                double czc = Convert.ToDouble(data["czc"]) * scale;//莫氏锥柄号
                double D = Convert.ToDouble(data["dcx"]) * scale;
                double d1 = Convert.ToDouble(data["dc"]) * scale;
                double l = Convert.ToDouble(data["oal"]) * scale;
                double l1 = Convert.ToDouble(data["lh"]) * scale;

                if (czc == 1)
                {
                    db = 12.065 * scale;
                    ds = 9.4 * scale;
                    tg = 0.04988;
                }
                if (czc == 2)
                {
                    db = 17.78 * scale;
                    ds = 14.6 * scale;
                    tg = 0.04995;
                }
                if (czc == 3)
                {
                    db = 23.825 * scale;
                    ds = 19.8 * scale;
                    tg = 0.05020;
                }
                if (czc == 4)
                {
                    db = 31.267 * scale;
                    ds = 25.9 * scale;
                    tg = 0.05194;
                }


                //double zc = 55.47;//锥长
                double zc = (db - ds) / tg;//锥长
                Vector2 v1 = new Vector2(-2, 0);
                Vector2 v2 = new Vector2(l + 2, 0);
                Vector2 v3 = new Vector2(0, d1 / 2);
                Vector2 v4 = new Vector2((D - d1) / 2 * Math.Tan((90 - jd / 2) * pi / 180), D / 2);
                Vector2 v5 = new Vector2(l1, v4.Y - (l1 - v4.X) / 30 / 2);
                Vector2 v6 = new Vector2(l-zc*71.68/55.47, db/2);
                Vector2 v7 = new Vector2(l - (zc * 69.69 / 55.47), db / 2);
                Vector2 v8 = new Vector2(v7.X + zc, ds / 2);
                Vector2 v9 = new Vector2(l - (zc * 9.21 / 55.47), ds * 2.58 / 14);
                Vector2 v10 = new Vector2(l, v9.Y);
                Vector2 v11 = new Vector2(v10.X, -v10.Y);
                Vector2 v12 = new Vector2(v9.X, -v9.Y);
                Vector2 v13 = new Vector2(v8.X, -v8.Y);
                Vector2 v14 = new Vector2(v7.X, -v7.Y);
                Vector2 v15 = new Vector2(v6.X, -v6.Y);
                Vector2 v16 = new Vector2(v5.X, -v5.Y);
                Vector2 v17 = new Vector2(v4.X, -v4.Y);
                Vector2 v18 = new Vector2(v3.X, -v3.Y);
                Vector2 v19 = new Vector2(0, d1 / 6);
                Vector2 v20 = new Vector2(v4.X, D * 8.26 / 28.58);
                Vector2 v21 = new Vector2(v5.X, D * 7.76 / 28.58);
                Vector2 v22 = new Vector2(l1 * 18.75 / 13.37, 0);
                Vector2 v23 = new Vector2(l1 * 18.06 / 13.37, -(D * 4.74 / 28.58));
                Vector2 v24 = new Vector2(v5.X, -(D * 3.78 / 28.58));
                Vector2 v25 = new Vector2(v4.X, -(D * 3.22 / 28.58));
                Vector2 v26 = new Vector2(0, -v19.Y);


                Line line1 = new Line(v1, v2);
                line1.Layer = centre;
                line1.Linetype = Linetype.DashDot;
                line1.LinetypeScale = 3;
                dxf.AddEntity(line1);

                LwPolyline line2 = new LwPolyline();
                line2.Vertexes.Add(new LwPolylineVertex(v3));
                line2.Vertexes.Add(new LwPolylineVertex(v4));
                line2.Vertexes.Add(new LwPolylineVertex(v5));
                line2.Vertexes.Add(new LwPolylineVertex(v6));
                line2.Vertexes.Add(new LwPolylineVertex(v7));
                line2.Vertexes.Add(new LwPolylineVertex(v8));
                line2.Vertexes.Add(new LwPolylineVertex(v9));
                line2.Vertexes.Add(new LwPolylineVertex(v10));
                line2.Vertexes.Add(new LwPolylineVertex(v11));
                line2.Vertexes.Add(new LwPolylineVertex(v12));
                line2.Vertexes.Add(new LwPolylineVertex(v13));
                line2.Vertexes.Add(new LwPolylineVertex(v14));
                line2.Vertexes.Add(new LwPolylineVertex(v15));
                line2.Vertexes.Add(new LwPolylineVertex(v16));
                line2.Vertexes.Add(new LwPolylineVertex(v17));
                line2.Vertexes.Add(new LwPolylineVertex(v18));
                line2.Vertexes.Add(new LwPolylineVertex(v3));
                line2.Vertexes[2].Bulge = Math.Tan(53 * pi / 180 / 4);
                line2.Vertexes[3].Bulge = Math.Tan(90 * pi / 180 / 4);
                line2.Vertexes[5].Bulge = Math.Tan(76 * pi / 180 / 4);
                line2.Vertexes[9].Bulge = Math.Tan(76 * pi / 180 / 4);
                line2.Vertexes[11].Bulge = Math.Tan(90 * pi / 180 / 4);
                line2.Vertexes[12].Bulge = Math.Tan(53 * pi / 180 / 4);
                fun.PolyFill(dxf, line2, 0.1, contour);


                LwPolyline line3 = new LwPolyline();
                line3.Vertexes.Add(new LwPolylineVertex(v19));
                line3.Vertexes.Add(new LwPolylineVertex(v20));
                line3.Vertexes.Add(new LwPolylineVertex(v21));
                line3.Vertexes.Add(new LwPolylineVertex(v22));
                line3.Vertexes.Add(new LwPolylineVertex(v23));
                line3.Vertexes.Add(new LwPolylineVertex(v24));
                line3.Vertexes.Add(new LwPolylineVertex(v25));
                line3.Vertexes.Add(new LwPolylineVertex(v26));
                line3.Vertexes.Add(new LwPolylineVertex(v19));
                line3.Vertexes[3].Bulge = Math.Tan(-61 * pi / 180 / 4);
                fun.PolyFill(dxf, line3, 0.1, contour);


                LwPolyline line4 = new LwPolyline();
                line4.Vertexes.Add(new LwPolylineVertex(v4));
                line4.Vertexes.Add(new LwPolylineVertex(v20));
                fun.PolyFill(dxf, line4, 0.1, contour);

                LwPolyline line5 = new LwPolyline();
                line5.Vertexes.Add(new LwPolylineVertex(v5));
                line5.Vertexes.Add(new LwPolylineVertex(v21));
                fun.PolyFill(dxf, line5, 0.1, contour);

                LwPolyline line6 = new LwPolyline();
                line6.Vertexes.Add(new LwPolylineVertex(v6));
                line6.Vertexes.Add(new LwPolylineVertex(v15));
                fun.PolyFill(dxf, line6, 0.1, contour);

                LwPolyline line7 = new LwPolyline();
                line7.Vertexes.Add(new LwPolylineVertex(v7));
                line7.Vertexes.Add(new LwPolylineVertex(v14));
                fun.PolyFill(dxf, line7, 0.1, contour);

                LwPolyline line9 = new LwPolyline();
                line9.Vertexes.Add(new LwPolylineVertex(v9));
                line9.Vertexes.Add(new LwPolylineVertex(v12));
                fun.PolyFill(dxf, line9, 0.1, contour);

                LwPolyline line10 = new LwPolyline();
                line10.Vertexes.Add(new LwPolylineVertex(v16));
                line10.Vertexes.Add(new LwPolylineVertex(v24));
                fun.PolyFill(dxf, line10, 0.1, contour);

                LwPolyline line11 = new LwPolyline();
                line11.Vertexes.Add(new LwPolylineVertex(v17));
                line11.Vertexes.Add(new LwPolylineVertex(v25));
                fun.PolyFill(dxf, line11, 0.1, contour);

                //标注
                double height = 1 * scale;
                double arrowsize = 1 * scale;
                double exline = 1 * scale;

                fun.dimrot1(dxf, v4, v17, 90, l * 0.4, height, arrowsize, exline, 0, "DCX=" + D / scale, "", "");
                fun.dimrot1(dxf, v3, v18, 90, l * 0.1, height, arrowsize, exline, 0, "DC=" + d1 / scale, "", "");
                fun.dimrot1(dxf, v3, v10, 0, l * 0.4, height, arrowsize, exline, 0, "OAL=" + l / scale, "", "");
                fun.dimrot1(dxf, v3, v5, 0, l * 0.2, height, arrowsize, exline, 0, "LH=" + l1 / scale, "", "");

                fun.jdbz2(dxf, new Line(v18, v17), new Line(v3, v4), l * 0.1, height, arrowsize, exline, "" + jd + "°", "", "");

                fun.jt(dxf, new Vector2(v17.X + (v16.X - v17.X) / 2, v17.Y + (v16.Y - v17.Y) / 2), -45, l1 / 3, 1, "1:30");
                fun.jt(dxf, new Vector2(v7.X + (v8.X - v7.X) / 2, v7.Y - (v7.Y - v8.Y) / 2), 45, l1 / 3, 1, "莫氏圆锥柄");


            }

            if (ccms == "msyzb" && jd == 60)//60°莫氏圆锥柄
            {
                //double D = 28.49;
                //double d1 = 6.03;
                //double l = 110.08;
                //double l1 = 24.01;

                //double czc = 1;
                double db = 0;
                double ds = 0;
                double tg = 0;

                double czc = Convert.ToDouble(data["czc"]) * scale;
                double D = Convert.ToDouble(data["dcx"]) * scale;
                double d1 = Convert.ToDouble(data["dc"]) * scale;
                double l = Convert.ToDouble(data["oal"]) * scale;
                double l1 = Convert.ToDouble(data["lh"]) * scale;

                if (czc == 1)
                {
                    db = 12.065 * scale;
                    ds = 9.4 * scale;
                    tg = 0.04988;
                }
                if (czc == 2)
                {
                    db = 17.78 * scale;
                    ds = 14.6 * scale;
                    tg = 0.04995;
                }
                if (czc == 3)
                {
                    db = 23.825 * scale;
                    ds = 19.8 * scale;
                    tg = 0.05020;
                }
                if (czc == 4)
                {
                    db = 31.267 * scale;
                    ds = 25.9 * scale;
                    tg = 0.05194;
                }


                double zc = (db - ds) / tg;//锥长
                Vector2 v1 = new Vector2(-2, 0);
                Vector2 v2 = new Vector2(l + 2, 0);
                Vector2 v3 = new Vector2(0, d1 / 2);
                Vector2 v4 = new Vector2((D - d1) / 2 * Math.Tan((90-jd/2) * pi / 180), D / 2);
                Vector2 v5 = new Vector2(l1, v4.Y - (l1 - v4.X) / 30 / 2);
                Vector2 v6 = new Vector2(l-zc*74.52/55.45, db/2);
                Vector2 v7 = new Vector2(l - (zc * 72.53 / 55.45), db / 2);
                Vector2 v8 = new Vector2(v7.X + zc, ds / 2);
                Vector2 v9 = new Vector2(l - (zc * 10.18 / 55.45), ds * 3.22 / 14.88);
                Vector2 v10 = new Vector2(l, v9.Y);
                Vector2 v11 = new Vector2(v10.X, -v10.Y);
                Vector2 v12 = new Vector2(v9.X, -v9.Y);
                Vector2 v13 = new Vector2(v8.X, -v8.Y);
                Vector2 v14 = new Vector2(v7.X, -v7.Y);
                Vector2 v15 = new Vector2(v6.X, -v6.Y);
                Vector2 v16 = new Vector2(v5.X, -v5.Y);
                Vector2 v17 = new Vector2(v4.X, -v4.Y);
                Vector2 v18 = new Vector2(v3.X, -v3.Y);
                Vector2 v19 = new Vector2(0, d1 / 6);
                Vector2 v20 = new Vector2(v4.X, D * 9.38 / 28.49);
                Vector2 v21 = new Vector2(v5.X, D * 8.5 / 28.49);
                Vector2 v22 = new Vector2(l1 * 28.58 / 24.01, 0);
                Vector2 v23 = new Vector2(l1 * 27.14 / 24.01, -(D * 4.39 / 28.49));
                Vector2 v24 = new Vector2(v5.X, -(D * 3.89 / 28.49));
                Vector2 v25 = new Vector2(v4.X, -(D * 3.16 / 28.49));
                Vector2 v26 = new Vector2(0, 0);


                Line line1 = new Line(v1, v2);
                line1.Layer = centre;
                line1.Linetype = Linetype.DashDot;
                line1.LinetypeScale = 3;
                dxf.AddEntity(line1);

                LwPolyline line2 = new LwPolyline();
                line2.Vertexes.Add(new LwPolylineVertex(v3));
                line2.Vertexes.Add(new LwPolylineVertex(v4));
                line2.Vertexes.Add(new LwPolylineVertex(v5));
                line2.Vertexes.Add(new LwPolylineVertex(v6));
                line2.Vertexes.Add(new LwPolylineVertex(v7));
                line2.Vertexes.Add(new LwPolylineVertex(v8));
                line2.Vertexes.Add(new LwPolylineVertex(v9));
                line2.Vertexes.Add(new LwPolylineVertex(v10));
                line2.Vertexes.Add(new LwPolylineVertex(v11));
                line2.Vertexes.Add(new LwPolylineVertex(v12));
                line2.Vertexes.Add(new LwPolylineVertex(v13));
                line2.Vertexes.Add(new LwPolylineVertex(v14));
                line2.Vertexes.Add(new LwPolylineVertex(v15));
                line2.Vertexes.Add(new LwPolylineVertex(v16));
                line2.Vertexes.Add(new LwPolylineVertex(v17));
                line2.Vertexes.Add(new LwPolylineVertex(v18));
                line2.Vertexes.Add(new LwPolylineVertex(v3));
                line2.Vertexes[2].Bulge = Math.Tan(53 * pi / 180 / 4);
                line2.Vertexes[3].Bulge = Math.Tan(90 * pi / 180 / 4);
                line2.Vertexes[5].Bulge = Math.Tan(66 * pi / 180 / 4);
                line2.Vertexes[9].Bulge = Math.Tan(66 * pi / 180 / 4);
                line2.Vertexes[11].Bulge = Math.Tan(90 * pi / 180 / 4);
                line2.Vertexes[12].Bulge = Math.Tan(53 * pi / 180 / 4);
                fun.PolyFill(dxf, line2, 0.1, contour);


                LwPolyline line3 = new LwPolyline();
                line3.Vertexes.Add(new LwPolylineVertex(v19));
                line3.Vertexes.Add(new LwPolylineVertex(v20));
                line3.Vertexes.Add(new LwPolylineVertex(v21));
                line3.Vertexes.Add(new LwPolylineVertex(v22));
                line3.Vertexes.Add(new LwPolylineVertex(v23));
                line3.Vertexes.Add(new LwPolylineVertex(v24));
                line3.Vertexes.Add(new LwPolylineVertex(v25));
                line3.Vertexes.Add(new LwPolylineVertex(v26));
                line3.Vertexes.Add(new LwPolylineVertex(v19));
                line3.Vertexes[3].Bulge = Math.Tan(-61 * pi / 180 / 4);
                fun.PolyFill(dxf, line3, 0.1, contour);


                LwPolyline line4 = new LwPolyline();
                line4.Vertexes.Add(new LwPolylineVertex(v4));
                line4.Vertexes.Add(new LwPolylineVertex(v20));
                fun.PolyFill(dxf, line4, 0.1, contour);

                LwPolyline line5 = new LwPolyline();
                line5.Vertexes.Add(new LwPolylineVertex(v5));
                line5.Vertexes.Add(new LwPolylineVertex(v21));
                fun.PolyFill(dxf, line5, 0.1, contour);

                LwPolyline line6 = new LwPolyline();
                line6.Vertexes.Add(new LwPolylineVertex(v6));
                line6.Vertexes.Add(new LwPolylineVertex(v15));
                fun.PolyFill(dxf, line6, 0.1, contour);

                LwPolyline line7 = new LwPolyline();
                line7.Vertexes.Add(new LwPolylineVertex(v7));
                line7.Vertexes.Add(new LwPolylineVertex(v14));
                fun.PolyFill(dxf, line7, 0.1, contour);

                LwPolyline line9 = new LwPolyline();
                line9.Vertexes.Add(new LwPolylineVertex(v9));
                line9.Vertexes.Add(new LwPolylineVertex(v12));
                fun.PolyFill(dxf, line9, 0.1, contour);

                LwPolyline line10 = new LwPolyline();
                line10.Vertexes.Add(new LwPolylineVertex(v16));
                line10.Vertexes.Add(new LwPolylineVertex(v24));
                fun.PolyFill(dxf, line10, 0.1, contour);

                LwPolyline line11 = new LwPolyline();
                line11.Vertexes.Add(new LwPolylineVertex(v17));
                line11.Vertexes.Add(new LwPolylineVertex(v25));
                fun.PolyFill(dxf, line11, 0.1, contour);

                //标注
                double height = 1 * scale;
                double arrowsize = 1 * scale;
                double exline = 1 * scale;

                fun.dimrot1(dxf, v4, v17, 90, l * 0.4, height, arrowsize, exline, 0, "DCX=" + D / scale, "", "");
                fun.dimrot1(dxf, v3, v18, 90, l * 0.1, height, arrowsize, exline, 0, "DC=" + d1 / scale, "", "");
                fun.dimrot1(dxf, v3, v10, 0, l * 0.4, height, arrowsize, exline, 0, "OAL=" + l / scale, "", "");
                fun.dimrot1(dxf, v3, v5, 0, l * 0.2, height, arrowsize, exline, 0, "LH=" + l1 / scale, "", "");

                fun.jdbz2(dxf, new Line(v18, v17), new Line(v3, v4), l * 0.1, height, arrowsize, exline, "" + jd + "°", "", "");

                fun.jt(dxf, new Vector2(v17.X + (v16.X - v17.X) / 2, v17.Y + (v16.Y - v17.Y) / 2), -45, l1 / 3, 1, "1:30");
                fun.jt(dxf, new Vector2(v7.X + (v8.X - v7.X) / 2, v7.Y - (v7.Y - v8.Y) / 2), 45, l1 / 3, 1, "莫氏圆锥柄");

            }




            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            Vector2 p0 = new Vector2(0, 0);


            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
}
